* Analysis: Part I
use "Part I_replication_data", clear

* Defining the sample
keep if sample==1
drop if country=="South Korea"
drop if country=="Israel"

* Figure 2
** M-L
twoway (scatter pre_50 pre_10, msymbol(circle_hollow) mlabsize("large") mcolor(black)) (function y=x, ra(.15 1) color(black)), ytitle("Support M", size("large")) xtitle("Support L", size("large")) xlabel(.2(.2)1, labsize("large")) ylabel(.2(.2)1, labsize("large") angle(horizontal)) ymtick(.2(.1)1) xmtick(.2(.1)1) legend(off)

** H-M
twoway (scatter pre_90 pre_50, msymbol(circle_hollow) mlabsize("large") mcolor(black)) (function y=x, ra(.15 1) color(black)), ytitle("Support H", size("large")) xtitle("Support M", size("large")) xlabel(.2(.2)1, labsize("large")) ylabel(.2(.2)1, labsize("large") angle(horizontal)) ymtick(.2(.1)1) xmtick(.2(.1)1) legend(off)

** H-L
twoway (scatter pre_90 pre_10, msymbol(circle_hollow) mlabsize("large") mcolor(black)) (function y=x, ra(.15 1) color(black)), ytitle("Support H", size("large")) xtitle("Support L", size("large")) xlabel(.2(.2)1, labsize("large")) ylabel(.2(.2)1, labsize("large") angle(horizontal)) ymtick(.2(.1)1) xmtick(.2(.1)1) legend(off)


xtset ccode year
 * Table 2
reg inter_socialspending_c2 pre_social_10, cluster(ccode)
reg inter_socialspending_c2 pre_social_50, cluster(ccode)
reg inter_socialspending_c2 pre_social_90, cluster(ccode)
reg inter_socialspending_c2 pre_social_10 pre_social_50 pre_social_90, cluster(ccode)
xtreg inter_socialspending_c2 pre_social_10, fe vce(robust)
xtreg inter_socialspending_c2 pre_social_50, fe vce(robust)
xtreg inter_socialspending_c2 pre_social_90, fe vce(robust)
xtreg inter_socialspending_c2 pre_social_10 pre_social_50 pre_social_90, fe vce(robust)

* Table 3
xtpcse inter_socialspending pre_10, p c(a) hetonly
xtpcse inter_socialspending pre_50, p c(a) hetonly
xtpcse inter_socialspending pre_90, p c(a) hetonly
xtpcse inter_socialspending pre_10 pre_50 pre_90, p c(a) hetonly 
xtpcse inter_socialspending pre_10 i.ccode, p c(a) hetonly
xtpcse inter_socialspending pre_50 i.ccode, p c(a) hetonly
xtpcse inter_socialspending pre_90 i.ccode, p c(a) hetonly
xtpcse inter_socialspending pre_10 pre_50 pre_90 i.ccode, p c(a) hetonly
 
***																***
* To prepare data for the analyses in Table 4, run code from here:*
***																***

* creating a measure of government partisanship:
g gov_partisan = (gov_right2-gov_left2)/100

* creating means by countries
bysort country: egen mean_gov_partisan =mean(gov_partisan)
bysort country: egen mean_pre_10 =mean(pre_10)
bysort country: egen mean_pre_50 =mean(pre_50)
bysort country: egen mean_pre_90 =mean(pre_90)


* predicting and extracting the intercepts
xtset ccode year
xtpcse inter_socialspending pre_50 i.ccode, p c(a) hetonly
keep if e(sample) 

encode country, g(ccode1)
xtset ccode1 year
xtpcse inter_socialspending pre_10 pre_50 pre_90  i.ccode1, p c(a) hetonly
margins, over(ccode1) at (pre_10=0  pre_50=0 pre_90=0)
mat m = r(b)
matrix list m

foreach n of numlist 1/21 {
g intercept_`n' = m[1,`n'] 
replace intercept_`n'=. if `n'!=ccode1
}

g intercept =.
foreach n of numlist 1/21 {
replace intercept = intercept_`n' if `n'==ccode1
drop intercept_`n'
}

duplicates drop intercept, force

***		***
* To here *
***		***

* Table 4
reg intercept mean_pre_10
reg intercept mean_pre_50 
reg intercept mean_pre_90 
reg intercept mean_pre_10 mean_pre_50 mean_pre_90 
reg intercept mean_pre_10 mean_gov_partisan 
reg intercept mean_pre_50 mean_gov_partisan
reg intercept mean_pre_90 mean_gov_partisan
reg intercept mean_pre_10 mean_pre_50 mean_pre_90 mean_gov_partisan
 
